package com.dd.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.entity.Employees;
import com.dd.entity.PageResult;
import com.dd.entity.dto.EmployeeQueryDTO;
import com.dd.service.IEmployeesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author dhd
 * @since 2024-12-09 10:44
 */
@RestController
@RequestMapping("/employees")
@Tag(name = "员工前端管理器", description = "员工接口")
public class EmployeesController {
    @Autowired
    private IEmployeesService employeesService;
    // 分页查询
    @GetMapping("/getList")
    @Operation(summary = "员工分页查询接口", description = "获取分页数据")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "2000", description = "请求成功"),
            @ApiResponse(responseCode = "2001", description = "请求失败")
    })
    public PageResult<Employees> getList(@Valid @RequestBody EmployeeQueryDTO employeeQueryDTO){
        return employeesService.getPage(employeeQueryDTO);
    }
    // 根据id查询
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询员工接口", description = "根据id查询员工")
    public Employees getById(@PathVariable @Parameter(name = "id", description = "员工id",required = true) Integer id){
        Employees employees = employeesService.getById(id);
        return employees;
    }
    // 新增
    @PostMapping
    @Operation(summary = "新增员工接口", description = "新增员工")
    public boolean add(@Parameter(name = "employees", description = "员工对象",required = true) Employees employees){
        boolean save = employeesService.save(employees);
        return save;
    }
    // 修改
    @PutMapping
    @Operation(summary = "修改员工接口", description = "修改员工")
    public boolean update(@Parameter(name = "employees", description = "员工对象",required = true) Employees employees){
        boolean update = employeesService.updateById(employees);
        return update;
    }
    // 删除
    @Operation(summary = "删除员工接口", description = "删除员工")
    @DeleteMapping("{id}")
    public boolean delete(@PathVariable @Parameter(name = "id", description = "员工id",required = true) Integer id){
        boolean delete = employeesService.removeById(id);
        return delete;
    }
}
